/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * <p>Project: jse2204 - T3
 * <p>Powered by webrx On 2022-09-29 14:16:33
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T3 implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        Integer sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        System.out.println(Thread.currentThread().getName());
        return sum;
    }

    public static void main(String[] args) throws Exception {
        //T3 t = new T3();
        Callable<Integer> t = new T3();
        FutureTask<Integer> ft = new FutureTask<>(t);
        Thread tt = new Thread(ft);
        tt.start();

        System.out.println(ft.get());


        FutureTask<Integer> ft2 = new FutureTask<>(t);
        Thread tt2 = new Thread(ft2);
        tt2.start();

        System.out.println(ft2.get());

        //2---------------------------------

        FutureTask<Integer> ff2 = new FutureTask<>(() -> {
            String tn = Thread.currentThread().getName();
            System.out.println(tn);
            int s = 0;
            for (int i = 1; i <= 1000; i++) s += i;
            return s;
        });
        new Thread(ff2,"求1-1000的和的线程").start();

        System.out.println(ff2.get());

    }
}


